from flask import Blueprint as _Blueprint

from src.extension.utils import check_types


class Blueprint(_Blueprint):

    def route(self, rules, **options):
        def decorator(f):
            endpoint = options.pop("endpoint", f.__name__)
            if check_types(rules, (tuple, list, str)):
                if isinstance(rules, tuple) or isinstance(rules, list):
                    for rule in rules: self.add_url_rule(rule, endpoint, f, **options)
                if isinstance(rules, str): self.add_url_rule(rules, endpoint, f, **options)
            return f

        return decorator
